package com.example.mrzhou.lvmm.view.fragment.surround;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.mrzhou.lvmm.R;
import com.example.mrzhou.lvmm.commom.base.BaseFragment;
import com.example.mrzhou.lvmm.entity.surround.holiday.Holiday;
import com.example.mrzhou.lvmm.presenter.surround.HolidayPrensenter;
import com.example.mrzhou.lvmm.view.adapter.surround.HolidayAdapter;
import com.example.mrzhou.lvmm.view.impl.surround.HolidayView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class SurHolidayFragment extends BaseFragment implements HolidayView {


    @BindView(R.id.rclv_sur_holiday)
    RecyclerView rclvSurHoliday;
    private List<Holiday.DataBean.RouteListBean> data = new ArrayList<>();
    private HolidayAdapter adapter;

    private static OnSurHolidayCallBack callBack;

    public SurHolidayFragment() {
        // Required empty public constructor
    }

    public static SurHolidayFragment newInstance(OnSurHolidayCallBack mcallback) {

        callBack =mcallback;
        Bundle args = new Bundle();

        SurHolidayFragment fragment = new SurHolidayFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_sur_holiday;
    }

    @Override
    protected void initView(View view) {
        ButterKnife.bind(this,view);
        rclvSurHoliday.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new HolidayAdapter(data,getContext());
        rclvSurHoliday.setAdapter(adapter);
        initData();
    }

    /**
     * --ebac37ac-7d6e-4b1a-abc2-ff477c77dea8
     Content-Disposition: form-data; name="keyword"
     Content-Length: 6

     北京
     --ebac37ac-7d6e-4b1a-abc2-ff477c77dea8
     Content-Disposition: form-data; name="pageNum"
     Content-Length: 1

     1
     --ebac37ac-7d6e-4b1a-abc2-ff477c77dea8
     Content-Disposition: form-data; name="pageSize"
     Content-Length: 2

     10
     --ebac37ac-7d6e-4b1a-abc2-ff477c77dea8
     Content-Disposition: form-data; name="routeType"
     Content-Length: 8

     FREETOUR
     --ebac37ac-7d6e-4b1a-abc2-ff477c77dea8
     Content-Disposition: form-data; name="homeSearch"
     Content-Length: 3

     YES
     --ebac37ac-7d6e-4b1a-abc2-ff477c77dea8
     Content-Disposition: form-data; name="version"
     Content-Length: 5

     1.0.0
     --ebac37ac-7d6e-4b1a-abc2-ff477c77dea8--

     */
    @Override
    protected void initData() {
        HolidayPrensenter prensenter = new HolidayPrensenter(this);
        Map<String,String> map = new HashMap<>();
        map.put("keyword", "北京");
        map.put("pageNum", "1");
        map.put("pageSize", "10");
        map.put("routeType", "FREETOUR");
        map.put("homeSearch", "YES");
        map.put("version", "1.0.0");
        prensenter.getHolidayData(map);
    }

    @Override
    public void onSuccess(Holiday holiday) {
        if (holiday!=null){
            data.addAll(holiday.getData().getRouteList());
            adapter.notifyDataSetChanged();
            callBack.onSurHolidayCallBack(holiday);
        }

    }

    @Override
    public void onFaiure(Throwable a) {

    }

    @Override
    public void onFinsh() {

    }

    public interface OnSurHolidayCallBack{
        void onSurHolidayCallBack(Holiday holiday);
    }
}
